package com.app.internationaltravel.controller;

import com.app.internationaltravel.dto.UserAddDto;
import com.app.internationaltravel.dto.UserFindDto;
import com.app.internationaltravel.dto.UserLoginDto;
import com.app.internationaltravel.service.intf.UserService;
import com.app.internationaltravel.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author 刘豆豆
 * @date 2022/12/12
 */

@RestController
@RequestMapping("/api/user/")
@Api(tags = "实现用户的相关操作")
@CrossOrigin //跨域
public class UserController {
  @Resource
  private UserService service;

  @ApiOperation(value = "查询全部用户",notes = "查询全部用户")
  @GetMapping("all.do")
  public R all(){
    return service.all();
  }

  @ApiOperation(value = "校验手机号是否可用",notes = "校验手机号是否可用")
  @GetMapping("checkphone.do")
  public R checkPhone(@ApiParam("手机号") String phone){
    return service.checkPhone(phone);
  }

  @ApiOperation(value = "校验用户名是否可用",notes = "校验用户名是否可用")
  @GetMapping("checkname.do")
  public R checkName(@ApiParam("用户名") String name){
    return service.checkName(name);
  }

  @ApiOperation(value = "实现用户注册",notes = "实现用户注册")
  @PostMapping("register.do")
  public R register(@RequestBody UserAddDto dto){
    return service.register(dto);
  }


  @ApiOperation(value = "实现用户账号登录",notes = "实现用户账号登录")
  @PostMapping("loginaccount.do")
  public R loginAccount(@RequestBody UserLoginDto dto){
    return service.loginAccount(dto);
  }

  @ApiOperation(value = "实现手机号验证码登录",notes = "实现手机号验证码登录")
  @PostMapping("logincode.do")
  public R loginCode(@RequestBody UserLoginDto dto){
    return service.loginCode(dto);
  }

  @ApiOperation(value = "校验令牌是否正确",notes = "校验令牌是否正确")
  @GetMapping("checktoken.do")
  public R checkToken(String phone,String token){
    return service.checkToken(phone, token);
  }

  @ApiOperation(value = "实现密码找回",notes = "实现密码找回")
  @PostMapping("findpass.do")
  public R findPass(@RequestBody UserFindDto dto){
    return service.findPass(dto);
  }

  @ApiOperation(value = "退出登录",notes = "退出登录")
  @GetMapping("loginout.do")
  public R loginOut(String phone){
    return service.loginOut(phone);
  }

}

